package com.googlecode.messwertepi.module;

import com.google.inject.Provider;
import com.googlecode.messwertepi.services.PrinterService.PrinterServiceException;

import javax.print.PrintService;
import javax.print.PrintServiceLookup;

/**
 * Created by eike on 15.07.14.
 */
public class PrintServiceProvider implements Provider<PrintService> {

    /**
     * This method returns the default print service of this system.
     *
     * @return the print service
     * @throws com.googlecode.messwertepi.services.PrinterService.PrinterServiceException if there is no default print service
     */
    @Override
    public PrintService get() {
        PrintService printService = PrintServiceLookup.lookupDefaultPrintService();

        if (printService == null) {
            throw new PrinterServiceException("Unable to retrieve default print service");
        }

        return printService;
    }
}
